﻿@{
	ViewBag.Title = Resources.SysActionMaster + ConstValues.strDash + Resources.HuiTongCIS;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.ActionName：<input id="selActionName" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
		@if ((User as ICISPrincipal).IsSSA || Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.SysActionMaster, RoleType.添加))
		{
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" onclick="addData();" plain="true">@Resources.Create</a>
		}
	</div>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.SysActionMaster" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01">@Resources.Create</h3>
			<form id="frmDetail" method="post">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.ActionName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="hidID" name="Id" />
							<input id="txtActionName" name="ActionName" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']" />
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.FunctionName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="ddlFunctionId" name="FunctionId" class="easyui-combobox" style="height:27px; width:300px;" data-options="required:true" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Authority：<input type="checkbox" id="chkAll" style="height:25px; vertical-align:top;" onchange="checkChange(this)" /></td>
						<td style="text-align: left;" class="w2 c4">
							<input type="checkbox" id="chkBrowse" name="Browse" style="height:25px; vertical-align:top;" />@Resources.Browse
							<input type="checkbox" id="chkAdd" name="Add" style="height:25px; vertical-align:top;" />@Resources.Create
							<input type="checkbox" id="chkModify" name="Modify" style="height:25px; vertical-align:top;" />@Resources.Modify
							<input type="checkbox" id="chkDelete" name="Delete" style="height:25px; vertical-align:top;" />@Resources.Delete
						</td>
						<td style="text-align: right;" class="w1 c3"></td>
						<td style="text-align: left;" class="w2 c4"></td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="ddlStatus" name="Status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtSort" name="Sort" class="easyui-numberbox" style="height:27px; width:300px;" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input id="txtRemark" name="Remark" class="easyui-textbox" style="height:50px; width:892px;" data-options="multiline:true, validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnWindowType" />
				<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("SysActionMaster");

	$(function () {
		$("#selActionName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});

		$("#ddlFunctionId").combobox({
			editable: false,
			required: true,
			valueField: "id",
			textField: "functionName",
			url: "@Url.Action(nameof(UtilityController.GetSysFunction), nameof(UtilityController).GetControllerName())",
		});

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(SysActionMasterController.GetData),
					nameof(SysActionMasterController).GetControllerName())",
			method: "get",
			singleSelect: true,
			fitColumns: true,
			width: $(window).width() - 285,
			height: $(window).height() - 120,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100, 
			pageList: [100, 200, 300, 400, 500],
			columns: [[
				{ field: "id", hidden: true },
				@if ((User as ICISPrincipal).IsSSA ||
					Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.SysActionMaster, RoleType.修改) ||
					Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.SysActionMaster, RoleType.删除))
				{
					<text>
					{
						field: "operate", title: "@Resources.Operate", align: "center", width: 150,
						formatter: function(value, rec) {
							var strInfo = "";
							var tmp = rec.actionName == null ? "" : rec.actionName.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
							@if ((User as ICISPrincipal).IsSSA || Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.SysActionMaster, RoleType.修改))
							 {
								<text>
								strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\""
									+ rec.id + "\")'>@Resources.Modify</a>";
								</text>
							}
							@if ((User as ICISPrincipal).IsSSA || Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.SysActionMaster, RoleType.删除))
							 {
								<text>
								if (strInfo != "") {
									strInfo += "&nbsp;|&nbsp;";
								}
								strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
									+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
								</text>
							}
							return strInfo;
						}
					},
					</text>
				}
				{ field: "actionName", title: "@Resources.ActionName", align: "center", sortable: true, width: 150 },
				{
	                		field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 100,
	                		formatter: function(value, rec) {
	                			if(value=="@ConstValues.Status.正常"){
	                				return "@Resources.Normal"
	                			}else{
	                				return "@Resources.Pause"
	                			}
	                		}
				},
				{ field: "sort", title: "@Resources.Sort", align: "center", sortable: true, width: 100},
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 200 },
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 100 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center", sortable: true, width: 100 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 100 },
			]],
			onBeforeLoad: function(param) {
				param.random = Math.random();
			},
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 110
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});
	});

	function searchData() {
		$("#dataGrid").datagrid("load", {
			SelActionName: $("#selActionName").textbox("getValue")
		});
	}

	function addData() {
		$("#hdnWindowType").val("add");
		$("#detailWindowTitle").text("@Resources.Create");
		$("#hidID").val("");
		$("#txtActionName").textbox("setValue", "");
		$("#ddlStatus").combobox("setValue", "@ConstValues.Status.正常");
		$("#txtSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtRemark").textbox("setValue", "");
		$("#frmDetail").find("input[type='checkbox']").attr("checked",false);
		$("#detailWindow").window("open");
		$("#ddlFunctionId").combobox("setValue", "");
	}

	function editData(id) {
		var url = "@Url.Action(nameof(SysActionMasterController.GetEditData),
				nameof(SysActionMasterController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#hdnWindowType").val("edit");
				$("#detailWindowTitle").text("@Resources.Modify");
				$("#hidID").val(id);
				$("#txtActionName").textbox("setValue", data.data.actionName);
				$("#ddlStatus").combobox("setValue", data.data.status);
				$("#txtSort").numberbox("setValue", data.data.sort);
				$("#txtRemark").textbox("setValue", data.data.remark);

				$("#chkBrowse").prop("checked", data.data.browse);
				$("#chkAdd").prop("checked", data.data.add);
				$("#chkModify").prop("checked", data.data.modify);
				$("#chkDelete").prop("checked", data.data.delete);
				if (data.data.browse && data.data.add && data.data.modify && data.data.delete) {
					$("#chkAll").prop("checked",true);
				} else {
					$("#chkAll").prop("checked",false);
				}
				$("#detailWindow").window("open");
				$("#ddlFunctionId").combobox("setValue", data.data.functionId);
			}
		});
	}

	function deleteData(id, name) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, name);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidID").val(id);
				$.post("@Url.Action(nameof(SysActionMasterController.Delete),
						nameof(SysActionMasterController).GetControllerName())",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	}

	function saveData() {
		var isValid = $("#frmDetail").form("validate");

		if (isValid) {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var token = $("#frmDetail").find("input[name='__RequestVerificationToken']").eq(0).val();
					var model = {};
					model.id = $("#hidID").val();
					model.actionName = $("#txtActionName").textbox("getValue");
					model.functionId = $("#ddlFunctionId").combobox("getValue");

					model.browse = $("#chkBrowse").prop("checked") ? true : false;
					model.add = $("#chkAdd").prop("checked") ? true : false;
					model.modify = $("#chkModify").prop("checked") ? true : false;
					model.delete = $("#chkDelete").prop("checked") ? true : false;

					model.status = $("#ddlStatus").combobox("getValue");
					model.sort = $("#txtSort").numberbox("getValue");
					model.remark = $("#txtRemark").textbox("getValue");

					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});

					var url;
					switch ($("#hdnWindowType").val())
					{
						case "add":
							url = "@Url.Action(nameof(SysActionMasterController.Create),
									nameof(SysActionMasterController).GetControllerName())";
							break;

						case "edit":
							url = "@Url.Action(nameof(SysActionMasterController.Modify),
									nameof(SysActionMasterController).GetControllerName())";
							break;
					}

					$.post(url,
					{
						"__RequestVerificationToken": token,
						"model": model,
					},
					function(data, textStatus, jqXHR) {
						layer.close(loading);
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							$("#detailWindow").window("close");
							$("#dataGrid").datagrid("reload");
						}
					});
				}
			});
		}
	}

	function checkChange(value) {
		if(value.checked) {
			$("#chkBrowse").prop("checked", true);
			$("#chkAdd").prop("checked", true);
			$("#chkModify").prop("checked", true);
			$("#chkDelete").prop("checked", true);
		} else {
			$("#chkBrowse").prop("checked", false);
			$("#chkAdd").prop("checked", false);
			$("#chkModify").prop("checked", false);
			$("#chkDelete").prop("checked", false);
		}
	}
</script>
}